/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.repair.mapper;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.repair.dto.*;
import org.springblade.modules.repair.dto.plan.PlanOrderHomePage4SearchDTO;
import org.springblade.modules.repair.dto.plan.PlanOrderHomePageSearchDTO;
import org.springblade.modules.repair.dto.statistical.by.CheckStatisticsPlanSimpleDTO;
import org.springblade.modules.repair.entity.MaintainCheckRecord;
import org.springblade.modules.repair.entity.MaintainPlanContent;
import org.springblade.modules.repair.vo.*;
import org.springblade.modules.repair.vo.elevator.ElevatorPartWorkVo;
import org.springblade.modules.repair.vo.plan.*;
import org.springblade.modules.repair.vo.plan.statistics.WxBuildingSimpleVO;
import org.springblade.modules.repair.vo.plan.statistics.WxElevatorSimpleVO;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 维保任务表 Mapper 接口
 *
 * @author ysq
 * @since 2022-03-28
 */
public interface MaintainPlanContentMapper extends BaseMapper<MaintainPlanContent> {

	/**
	 * 自定义分页
	 * @param planContentSearchDTO
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<PlanContentElevatorVo> selectMaintainPlanContent(@Param("planContentSearchDTO") PlanContentSearchDTO planContentSearchDTO,@Param("tenantId") String tenantId);

	/**
	 * 获取已经完成的工单列表
	 * @param planContentSearchDTO
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<PlanContentElevatorVo> getFinishPlanList(@Param("planContentSearchDTO") PlanContentSearchDTO planContentSearchDTO,@Param("tenantId") String tenantId);

	/**
	 * 获取维保类型数量
	 * @param planContentSearchDTO :查询条件
	 * @return 数据集
	 */
	List<MaintainPlanContentTypeCountVo> getplanContentType(@Param("planContentSearchDTO") PlanContentSearchDTO planContentSearchDTO);


    List<PlanDetailLocationTypeVO> selectPlanDetailLocationType(@Param("templateIds") List<Long> templateIds);

	List<Long> selectPlanTemplateTltChildrenIds(@Param("tltId") Long tltId, @Param("templateIds") List<Long> templateIds);

	Integer selectPlanWorItemCount(@Param("tltChildrenIds")List<Long> tltChildrenIds,@Param("templateIds") List<Long> templateIds);

	List<PlanTemplateContentVO> selectPlanTemplateContent(@Param("tltIds")List<Long> tltIds, @Param("templateId") Long templateId);

	List<PlanTemplateTypeVO> selectPlanTemplateType(@Param("tltIds")List<Long> tltIds, @Param("templateId") Long templateId);

	List<PlanTemplateContentVO> selectPlanTemplateContent2(@Param("tltId")Long tltId, @Param("templateId") Long templateId);

	/**
	 * 根据任务id获取保养位置
	 * @param planId
	 * @return
	 */
    List<String> getLocationTypeOfplanId(@Param("planId") Long planId);

    List<Long> listUserPlan(@Param("typeStatus") Integer typeStatus,@Param("planId") Long planId,@Param("userId") Long userId);

    List<PlanCountVO> countCheckPlanStatus(@Param("planIds") List<Long> planIds);

    List<PlanCountVO> countCheckPlanSign(@Param("planIds") List<Long> planIds,@Param("userIds") List<Long> userIds);

	List<Long> selectPlanIdsByUsers(@Param("userIds") List<Long> userIds, @Param("startTime") String startTime, @Param("endTime") String endTime,@Param("typeStatus") int typeStatus);

	List<PlanCountVO> countCheckPlanDuration(@Param("planIds") List<Long> planIds);

	List<PlanCountVO> countCheckPlanTimeliness(@Param("planIds") List<Long> planIds);

	List<PlanDataPageVO> selectPlanList(@Param("planIds") List<Long> planIds, @Param("queryDTO") CheckPlanPageQueryDTO queryDTO, IPage<PlanDataPageVO> page);

	List<PlanDataPageVO> selectScoreList(@Param("userIds") List<Long> userIds, @Param("startTime") String startTime, @Param("endTime") String endTime, IPage<PlanDataPageVO> page);

	@InterceptorIgnore(tenantLine = "on")
	List<String> listPlanTemplateName(@Param("planId") Long planId);

	Long selectPlanCount(@Param("planIds") List<Long> planIds, @Param("queryDTO") CheckPlanPageQueryDTO queryDTO);

	List<MalFunctionPlanPageVO> selectMalFunctionPlanPage(@Param("planIds") List<Long> planIds, @Param("queryDTO") CheckPlanPageQueryDTO queryDTO, IPage<MalFunctionPlanPageVO> page);

	Long selectMalPlanCount(@Param("planIds") List<Long> planIds,@Param("queryDTO") CheckPlanPageQueryDTO queryDTO);

    LastPlanVO selectElevatorLastPlan(@Param("elevatorId") Long elevatorId,@Param("planId") Long planId);

	@InterceptorIgnore(tenantLine = "on")
	String getPlanTemplateName(@Param("planId") Long planId);

    ElevatorSimpleInfoVO getElevatorSimpleInfo(@Param("planId") Long planId);

    int countCorrelationPlan(@Param("planId") Long planId);

    HashMap<String,Object> countElevatorPlan(@Param("queryDTO") CheckPlanPageQueryDTO queryDTO);

	IPage<PlanDataPageVO> selectElevatorCheckPlanList(@Param("queryDTO") CheckPlanPageQueryDTO queryDTO, IPage<Object> page);

	IPage<MalFunctionPlanPageVO> selectElevatorMalfunctionPlanList(@Param("queryDTO") CheckPlanPageQueryDTO queryDTO, IPage<Object> page);

	IPage<MalFunctionPlanPageVO> selectElevatorPartsPlanList(@Param("queryDTO") CheckPlanPageQueryDTO queryDTO, IPage<Object> page);

	Integer selectUserPlanStatusToStart(@Param("userId") Long userId);

	Integer selectUserPlanStatusUnderway(@Param("userId") Long userId);

	Integer selectUserPlanStatusFinished(@Param("userId") Long userId);

    HomePlanApproveCountVO selectUserPlanApprove(@Param("userId") Long userId);

	HomePlanApplyCountVO selectUserPlanApply(@Param("userId") Long userId);

	HomeDeptBuildingPlanCountVO countPlanByUser(@Param("userIds") List<Long> userIds);

	HomeDeptBuildingPlanCountVO countBuildingByUser(@Param("userIds") List<Long> userIds);

	@InterceptorIgnore(tenantLine = "on")
	IPage<PlanDataPageVO> elevatorPlanHistoryBy(@Param("queryDTO") ByPlanHistoryDTO queryDTO, IPage<PlanDataPageVO> page);

	IPage<MalFunctionPlanPageVO> elevatorPlanHistoryWx(@Param("queryDTO") WxPlanHistoryDTO queryDTO, IPage<MalFunctionPlanPageVO> page);

	IPage<MalFunctionPlanPageVO> elevatorPlanHistoryPj(@Param("queryDTO") PjPlanHistoryDTO queryDTO, IPage<MalFunctionPlanPageVO> page);

	List<PlanDatePageVO> elevatorPlanHistoryFinishBy(@Param("queryDTO") ByPlanHistoryDTO queryDTO,@Param("tenantId") String tenantId);

	List<PlanDatePageVO> elevatorPlanHistoryUnfinishedBy(@Param("queryDTO") ByPlanHistoryDTO queryDTO,@Param("tenantId") String tenantId);

	List<PlanDatePageVO> elevatorPlanHistoryFinishWx(@Param("queryDTO") WxPlanHistoryDTO queryDTO);

	List<PlanDatePageVO> elevatorPlanHistoryUnfinishedWx(@Param("queryDTO") WxPlanHistoryDTO queryDTO);

	List<PlanDatePageVO> elevatorPlanHistoryFinishPj(@Param("queryDTO") PjPlanHistoryDTO queryDTO);

	List<PlanDatePageVO> elevatorPlanHistoryUnfinishedPj(@Param("queryDTO") PjPlanHistoryDTO queryDTO);

	SimpleElevatorPlanInfoDTO getSimpleElevatorPlanInfo(@Param("planId") Long planId);

    Map<String, Object> selectPlanSimpleDetailByElevator(@Param("elevatorId") Long elevatorId,@Param("planDate") Date planDate);

    List<MaintainPlanContent> listByUserDate(@Param("queryDTO") PlanCheckStatisticsQueryDTO queryDTO,@Param("userIds") List<Long> userIds);

	List<CheckStatisticsPlanSimpleDTO> listPlanExtByUserDate(@Param("queryDTO") PlanCheckStatisticsQueryDTO queryDTO, @Param("userIds") List<Long> userIds);

	/**
	 * 获取首页工单各种类型进行中的数量
	 * @param beginTime 开始时间
	 * @param endDate 结束时间
	 * @param userId 用户id
	 * @param tenantId
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine = "on")
    List<MaintainPlanContent> getPlanTypeStatistic(@Param("beginTime") DateTime beginTime, @Param("endDate") Date endDate, @Param("userId") Long userId,@Param("tenantId")  String tenantId);

	/**
	 * 个人工单维修列表逻辑调整
	 * @param queryDTO 查询条件DTO
	 * @param page 分页参数
	 * @return 分页结果
	 */
    IPage<MalFunctionPlanPageVO> elevatorPlanHistoryRepair(@Param("queryDTO") RepairPlanHistoryDTO queryDTO, IPage<MalFunctionPlanPageVO> page);


	IPage<PlanDataPageVO> elevatorPlanHistoryBySkip(@Param("queryDTO") ByPlanHistorySkipDTO queryDTO, IPage<PlanDataPageVO> page);


	IPage<MalFunctionPlanPageVO> elevatorPlanHistoryPjSkip(@Param("queryDTO") PjPlanHistorySkipDTO queryDTO, IPage<MalFunctionPlanPageVO> page);

	/**
	 * 获取首页救援工单的列表
	 * @param planContentSearchDTO 查询条件
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<PlanContentElevatorVo> getRescueHomeList(@Param("planContentSearchDTO") PlanContentSearchDTO planContentSearchDTO);

	/**
	 * 获取我的申请-维修报障信息
	 * @param approveStatus 审核状态
	 * @param page 分页信息
	 * @param userId 用户id
	 * @return 维修报障列表
	 */
	IPage<MyApproveVO> getMyApproveList(Long userId, Integer approveStatus, IPage<MyApproveVO> page);

	/**
	 * 获取问题描述字典值
	 * @param dictKey 字典Key
	 * @return 字典值
	 */
	String dictValue(String dictKey);

	@InterceptorIgnore(tenantLine = "on")
	List<SimpleTemplateInfoVO> getPlanTemplateSimpleInfo(Long planId);

	/**
	 * 获取工单日历下载工单信息
	 * @param calendarData
	 * @return
	 */
	List<PlanInfoDownExcelVO> getDatePlanInfoListDownExcel(@Param("calendarData") MaintainPlanCalendarDataDownDTO calendarData);

	/**
	 * 获取工单日历表list
	 * @param calendarData
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<MaintainPlanContent> maintainPlanCalendarList(@Param("calendarData") MaintainPlanCalendarDataDTO calendarData);

    List<PlanSimpleInfoDTO> listPlanSimpleByElevatorIds(@Param("queryDTO") PlanCheckStatisticsQueryDTO queryDTO, @Param("elevatorIds") List<Long> elevatorIds, @Param("typeStatus") Integer typeStatus);

	List<WxBuildingSimpleVO> selectWxRepetitionBuildingSimpleByIds(@Param("buildingIds") List<Long> buildingIds, IPage<WxBuildingSimpleVO> page);

	List<WxElevatorSimpleVO> getElevatorSimpleAndWxPlan(@Param("elevatorIds") List<Long> elevatorIds, @Param("queryDTO") PlanCheckStatisticsQueryDTO queryDTO);

	@InterceptorIgnore(tenantLine = "on")
    List<ElevatorFilesPlanListVO> selectElevatorFilesAllPlanBy(@Param("elevatorId") Long elevatorId,@Param("startDate") String startDate,@Param("endDate") String endDate);

	@InterceptorIgnore(tenantLine = "on")
	List<ElevatorFilesPlanListVO> selectElevatorFilesAllPlanWx(@Param("elevatorId") Long elevatorId,@Param("startDate") String startDate,@Param("endDate") String endDate);

	@InterceptorIgnore(tenantLine = "on")
	List<ElevatorFilesPlanListVO> selectElevatorFilesAllPlanPj(@Param("elevatorId") Long elevatorId,@Param("startDate") String startDate,@Param("endDate") String endDate);

	@InterceptorIgnore(tenantLine = "on")
	List<ElevatorFilesPlanListVO> selectElevatorFilesAllPlanJy(@Param("elevatorId") Long elevatorId,@Param("startDate") String startDate,@Param("endDate") String endDate);

	@InterceptorIgnore(tenantLine = "on")
	List<ElevatorPartWorkVo> getWorkListBy(@Param("elevatorId") Long elevatorId,@Param("partsId")  Long partsId,@Param("startDate")  String startDate,@Param("endDate")  String endDate);

	@InterceptorIgnore(tenantLine = "on")
	List<MaintainCheckRecord> getWorkImageList(@Param("checkHistoryIds") List<Long> ids);

	@InterceptorIgnore(tenantLine = "on")
	List<ElevatorPartWorkVo> getWorkListWx(@Param("elevatorId") Long elevatorId,@Param("partsId")  Long partsId, @Param("floorStandIds") Long floorStandIds, @Param("startDate")  String startDate,@Param("endDate")  String endDate);

	@InterceptorIgnore(tenantLine = "on")
	List<ElevatorPartWorkVo> getWorkListPj(@Param("elevatorId") Long elevatorId,@Param("partsId")  Long partsId, @Param("floorStandIds") Long floorStandIds, @Param("startDate")  String startDate,@Param("endDate")  String endDate);

	@InterceptorIgnore(tenantLine = "on")
    int getWorkListPjCount(@Param("elevatorId") Long elevatorId,@Param("partsId")  Long partsId, @Param("floorStandIds") Long floorStandIds);

	@InterceptorIgnore(tenantLine = "on")
	int getWorkListWxCount(@Param("elevatorId") Long elevatorId,@Param("partsId")  Long partsId, @Param("floorStandIds") Long floorStandIds);

	@InterceptorIgnore(tenantLine = "on")
	int getWorkListByCount(@Param("elevatorId") Long elevatorId,@Param("partsId")  Long partsId);

	@InterceptorIgnore(tenantLine = "on")
	int selectElevatorPlanTotal(@Param("elevatorId") Long elevatorId);


	/**
	 * 首页的事务工单列表
	 * @param planContentSearchDTO 查询条件
	 * @param tenantId 租户
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<PlanContentElevatorVo> planAffairList(@Param("planContentSearchDTO") PlanContentSearchDTO planContentSearchDTO,@Param("tenantId") String tenantId);


	/**
	 * 获取质检工单
	 * @param planContentSearchDTO 查询条件
	 * @param tenantId 租户id
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine = "on")
    List<PlanContentElevatorVo> planCheckList(@Param("planContentSearchDTO") PlanContentSearchDTO planContentSearchDTO,@Param("tenantId")  String tenantId);

	/**
	 * 电梯信息
	 * 维保历史-事务工单列表
	 * @param elevatorId:电梯id
	 * @param startDate:开始时间
	 * @param endDate 结束时间
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<ElevatorFilesPlanListVO> selectElevatorFilesAllPlanSw(Long elevatorId, String startDate, String endDate);

	/**
	 * 电梯信息
	 * 维保历史-质检工单列表
	 * @param elevatorId:电梯id
	 * @param startDate:开始时间
	 * @param endDate 结束时间
	 * @return 数据集
	 */
	List<ElevatorFilesPlanListVO> selectElevatorFilesAllPlanZj(Long elevatorId, String startDate, String endDate);

	/**
	 * 获取首页数据2.0
	 * @param searchDTO
	 * @param page
	 * @return
	 */
    List<PlanOrderHomePageVO> planOrderHomePage(@Param("search") PlanOrderHomePageSearchDTO searchDTO, IPage<PlanOrderHomePageVO> page);

	/**
	 * 获取首页数据3.0
	 * @param searchDTO
	 * @param page
	 * @return
	 */
	List<PlanHomeDataVO> planOrderHomePageV3(@Param("search") PlanOrderHomePageSearchDTO searchDTO, @Param("page") IPage<PlanHomeDataVO> page);

	List<PlanOrderHomePageVO> planOrderByIds(@Param("planIds") String planIds, @Param("curUserId") Long curUserId);

	/**
	 * 获取首页数据4.0
	 */
	List<PlanHomeV4DataVO> planOrderHomePageV4(@Param("search") PlanOrderHomePage4SearchDTO searchDTO, @Param("page") IPage<PlanHomeV4DataVO> page);

	/**
	 * 获取首页数据4.0-根据planIds查询工单详情
	 * @param planIds
	 * @param curUserId
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<PlanOrderHomePageV4VO> planOrderV4ByIds(@Param("planIds") List<Long> planIds, @Param("curUserId") Long curUserId);

	/**
	 * 获取首页数据4.0-获取已经完成的工单列表
	 * @param planContentSearchDTO
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<PlanFinishOrderHomePageV4VO> getFinishPlanListV4(@Param("planContentSearchDTO") PlanOrderHomePage4SearchDTO planContentSearchDTO,@Param("tenantId") String tenantId);

	/**
	 * 查询保养工单详情
	 * @param planId
	 * @return
	 */
	ByPlanOrderDetailVO selectByPlanOrderDetail(@Param("planId") Long planId);

	/**
	 * 来源工单列表
	 * @param planId 当前工单id
	 * @return
	 */
    List<Long> getFromPlanIdByOwnId(Long planId);

	List<PlanTemplateContentVO> selectPlanTemplateContentList(@Param("planId") Long planId);

    ElevatorRescueRobotSimpleVO getElevatorSimpleInfoByPlanId(Long planId);

	List<ElevatorPlanUserDTO> selectPlanUserOverdueCount(@Param("userId") Long userId);

	List<ElevatorFilesPlanListVO> selectElevatorFilesAllPlanZg(@Param("elevatorId") Long elevatorId,@Param("startDate") String startDate,@Param("endDate") String endDate);

	/**
	 * 救援大屏个人详情工单统计
	 * @param userIds
	 * @return
	 */
	List<MaintainPlanContent> screenUserPlanStatisticsList(@Param("userIds") List<Long> userIds);
}
